package com.rxyl.love.petdoctor.acticity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.rxyl.love.petdoctor.R;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;

public class MainWebActivity extends AppCompatActivity {

    private WebView webView;
    private TextView tv_lable;
    private ImageView iv_back, iv_share;
    private WebSettings webSettings;
    private String lable;
    private String mainUrl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_view);
        initView();
        initData();
    }


    private void initView() {
        webView = (WebView) findViewById(R.id.bannerWebViews);
        tv_lable = (TextView) findViewById(R.id.tv_webview_lable);
        iv_back = (ImageView) findViewById(R.id.iv_webview_back);
        iv_share = (ImageView) findViewById(R.id.tv_webview_share);

        webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        webView.setWebViewClient(new WebViewClient() {

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });

        iv_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareSDK.initSDK(MainWebActivity.this);

                OnekeyShare oks = new OnekeyShare();

                //关闭sso授权
                oks.disableSSOWhenAuthorize();

                oks.setTitle("爱宠医生");

                oks.setText(lable);

                //oks.setImagePath();
                oks.setImageUrl("http://c-56245a3c7019c90ad5f63de5.image.alimmdn.com/2016-01-06/f9dd14119226e3b199f040f456de376b@360w_360h_1e_1c_75Q");

                oks.setTitleUrl(mainUrl);

                oks.show(MainWebActivity.this);
            }
        });

        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initData() {
        Intent intent = getIntent();
        mainUrl = intent.getStringExtra("mainUrl");
        lable = intent.getStringExtra("lable");
        Log.e("ssss", mainUrl);
        webView.loadUrl(mainUrl);
        tv_lable.setText(lable);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        webView.destroy();
    }
}
